package com.tenglong.teacher.ui.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.tenglong.teacher.R;
import com.tenglong.teacher.data.resultInfo.BaseStudentSignInfo;
import com.tenglong.teacher.ui.adapter.viewholder.StudentSignHeaderViewHolder;
import com.tenglong.teacher.ui.adapter.viewholder.StudentViewHolder;
import com.tenglong.teacher.ui.adapter.viewholder.base.BaseViewHolder;

import java.util.List;

public class StudentAdapter extends RecyclerView.Adapter<BaseViewHolder<BaseStudentSignInfo>> {
    private List<BaseStudentSignInfo> infos;
    private StudentListener listener;

    public StudentAdapter(List<BaseStudentSignInfo> infos) {
        this.infos = infos;
    }

    @NonNull
    @Override
    public BaseViewHolder<BaseStudentSignInfo> onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        switch (viewType) {
            case 0:
                return new StudentViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.student_sign_item_layout, parent, false), listener);
            default:
                return new StudentSignHeaderViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.student_sign_header_layout, parent, false), listener);
        }
    }

    @Override
    public void onBindViewHolder(@NonNull BaseViewHolder<BaseStudentSignInfo> holder, int position) {
        holder.setLayoutInfo(infos.get(position));
    }

    @Override
    public int getItemViewType(int position) {
        return infos.get(position).isHeader ? 1 : 0;
    }

    @Override
    public int getItemCount() {
        return infos.size();
    }

    public void setOnItemStudentListener(StudentListener listener) {
        this.listener = listener;
    }

    public interface StudentListener {
        void onBatchOperation(int position);
        String getClassId();
        void refreshPeopleNum();
        void onClickClassBegin(int position,boolean isClassBegin);
        void onRecordPosition(int position);
        String getClassType();
        void toPhotoAlbum();
        void toShoot();
        boolean getSignState();
        void getPublishHomeWorkState();
    }
}
